<template>
  <div class="goods-list">
    <div class="goods-item" v-for="item in goodslist" :key="item.id" @click="getgoodsinfo(item.id)">
      <img :src="item.img_url" alt="">
      <h5>{{item.title}}</h5>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.sell_price}}</span>
          <span class="pre">￥{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
    <mt-button type="primary" size="large" plain @click="getMore">加载更多</mt-button>
    
  </div>
</template>
<script>
import axios from 'axios'
export default {
  data(){
    return{
      pageindex:1,
      goodslist:[]

    }
  },
  created(){
    this.getgoodslist()
  },
  methods:{
    getgoodslist(){
      axios.get("api/getgoods?pageindex="+this.pageindex).then(res=>{
        this.goodslist=this.goodslist.concat(res.data.message)
      })
    },
    getMore(){
      this.pageindex++;
      this.getgoodslist();

    },
    //编程式导航
    getgoodsinfo(id){
      this.$router.push("/home/goods/goodsInfo/"+id)
    }
  }
}
</script>

<style lang="less" scoped>
  .goods-list{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 7px;
    .goods-item{
      display: flex;
      width: 49%;
      min-height: 293px;
      border: 1px solid #ccc;
      margin: 4px 0;
      padding: 2px;
      flex-direction:column ;
      justify-content: space-between;
      img{
        width: 100%;
      }
      h5{
        font-size: 15px;
        color: #000;
      }
      .info{
        background-color:rgba(0,0,0,0.1);
        .price{
          .now{
            font-size: 16px;
            font-weight: 700;
            color: #f00;
            padding-right: 15px;
          }
          .pre{
            font-size: 13px;
            text-decoration: line-through;
          }
        }
        .sell{
          display: flex;
          justify-content: space-between;

        }
      }
    }
  }
</style>